<template>
  <div class='ele-body ele-body-card'>
    <!-- 顶部卡片 -->
    <a-card
      :bordered='true'
      :body-style="{padding: '20px'}">
      <div class='ele-cell workplace-user-card'>
        <div class='ele-cell-content ele-cell'>
          <a-progress :width='70' type='circle' :percent='100' :format="() => '柜子'" />
          <div class='ele-cell-content'>
            <h4 class='ele-elip'>柜子号：{{ data.recordId }}</h4>
            <div class='ele-elip ele-text-secondary'>
              <clock-circle-outlined />
              <em>{{ data.deviceTime }}</em>
            </div>
          </div>
        </div>
      </div>
    </a-card>

    <a-card
      :bordered='true'
      :body-style="{padding: '20px'}">
      <a-form
        ref='form'
        :model='form'
        :rules='rules'
        :label-col='{ md: { span: 10 }, sm: { span: 24 } }'
        :wrapper-col='{ md: { span: 14 }, sm: { span: 24 } }'
        @submit='saveConfigToCmdQueue'
      >
        <a-row :gutter='8'>
          <a-col :md='12' :sm='24' :xs='24'>
            <!--<a-form-item label='总开关' name='masterSwitch'>
              <a-switch
                checked-children='开'
                un-checked-children='关'
                autoFocus='false'
                :checked='switchform.masterSwitchCheck'
                @change='masterSwitchChange'
              />
            </a-form-item>-->
            <a-form-item label='调试模式' name='debugModel'>
              <a-switch
                checked-children='开'
                un-checked-children='关'
                autoFocus='false'
                :checked='switchform.debugModelCheck'
                @change='debugModelChange'
              />
            </a-form-item>
            <a-form-item  label='CO2传感器开关' name='cotwoSwitch'>
              <a-switch
                checked-children='开'
                un-checked-children='关'
                autoFocus='false'
                :checked='switchform.cotwoSwitchCheck'
                @change='cotwoSwitchChange'
              />
            </a-form-item>
            <a-form-item  label='NH3传感器开关' name='nhthreeSwitch'>
              <a-switch
                checked-children='开'
                un-checked-children='关'
                autoFocus='false'
                :checked='switchform.nhthreeSwitchCheck'
                @change='nhthreeSwitchChange'
              />
            </a-form-item>
            <a-form-item  label='H2S传感器开关' name='htwosSwitch'>
              <a-switch
                checked-children='开'
                un-checked-children='关'
                autoFocus='false'
                :checked='switchform.htwosSwitchCheck'
                @change='htwosSwitchChange'
              />
            </a-form-item>
            <a-form-item  label='CH4传感器开关' name='methaneSwitch'>
              <a-switch
                checked-children='开'
                un-checked-children='关'
                autoFocus='false'
                :checked='switchform.methaneSwitchCheck'
                @change='methaneSwitchChange'
              />
            </a-form-item>
            <a-form-item label='风机的控制模式' name='fanModel'>
              <a-radio-group v-model:value='form.fanModel'>
                <a-radio :value='1'>
                  手动模式
                </a-radio>
                <a-radio :value='2'>
                  温控模式
                </a-radio>
              </a-radio-group>
            </a-form-item>
            <a-form-item v-if='form.fanModel == 1' label='风机手动控制开关' name='fanHandSwitch'>
              <a-switch
                checked-children='开'
                un-checked-children='关'
                autoFocus='false'
                :checked='switchform.fanHandSwitchCheck'
                @change='fanHandSwitchChange'
              />
            </a-form-item>
            <a-form-item v-if='form.fanModel == 2' label='风机温控模式下启动温度(℃):' name='fanTempCtoStart'>
              <a-input v-model:value='form.fanTempCtoStart' placeholder='精确到小数点后1位' allow-clear />
            </a-form-item>
            <a-form-item v-if='form.fanModel == 2' label='风机温控模式下停止温度(℃):' name='fanTempCtoOff'>
              <a-input v-model:value='form.fanTempCtoOff' placeholder='精确到小数点后1位' allow-clear />
            </a-form-item>
            <a-form-item label='风机在电磁阀打开前提前多少秒关闭(秒):' name='fanShutdownTime'>
              <a-input style="width: 70%" v-model:value='form.fanShutdownTime' placeholder='单位秒' allow-clear />
              <a-alert message="范围从0到60" style="margin-top:1px;font-size: 9px;padding:2px 3px;width: 70%" type="info" show-icon />
            </a-form-item>
            <a-form-item label='水泵在喷淋之前多长时间打开(秒):' name='pumpOpenTime'>
              <a-input  style="width: 70%" v-model:value='form.pumpOpenTime' placeholder='单位秒' allow-clear />
              <a-alert message="范围从0到60" style="margin-top:1px;font-size: 9px;padding:2px 3px;width: 70%" type="info" show-icon />
            </a-form-item>
          </a-col>

          <a-col :md='12' :sm='24' :xs='24'>
            <a-form-item label='温度报警下限(℃):' name='tempAlarmLow'>
              <a-input v-model:value='form.tempAlarmLow' placeholder='精确到小数点后1位' allow-clear />
              <a-alert message="精确到小数点后1位,范围从-500到900" style="margin-top:1px;font-size: 9px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='温度报警上限(℃):' name='tempAlarmHigh'>
              <a-input v-model:value='form.tempAlarmHigh' placeholder='精确到小数点后1位' allow-clear />
              <a-alert message="精确到小数点后1位,范围从-500到900" style="margin-top:1px;font-size: 9px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='湿度报警下限(%RH):' name='humAlarmLow'>
              <a-input v-model:value='form.humAlarmLow' placeholder='精确到小数点后1位' allow-clear />
              <a-alert message="精确到小数点后1位,范围从0到1000" style="margin-top:1px;font-size: 9px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='湿度报警上限(%RH):' name='humAlarmHigh'>
              <a-input v-model:value='form.humAlarmHigh' placeholder='精确到小数点后1位' allow-clear />
              <a-alert message="精确到小数点后1位,范围从0到1000" style="margin-top:1px;font-size: 9px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='温湿度报警检测时长(秒):' name='tempHumCheckTime'>
              <a-input v-model:value='form.tempHumCheckTime' placeholder='请输入温湿度报警检测时长' allow-clear />
            </a-form-item>
            <a-form-item label='甲烷报警下限(%LEL):' name='methaneAlarmLow'>
              <a-input v-model:value='form.methaneAlarmLow' placeholder='请输入甲烷报警下限' allow-clear />
              <a-alert message="范围从0到1000" style="margin-top:1px;font-size: 9px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='甲烷报警上限(%LEL):' name='methaneAlarmHigh'>
              <a-input v-model:value='form.methaneAlarmHigh' placeholder='请输入甲烷报警上限' allow-clear />
              <a-alert message="范围从0到1000" style="margin-top:1px;font-size: 9px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='甲烷报警检测时长(秒):' name='methaneCheckTime'>
              <a-input v-model:value='form.methaneCheckTime' placeholder='请输入甲烷报警检测时长' allow-clear />
            </a-form-item>
            <a-form-item label='CO2报警下限(ppm):' name='cotwoLow'>
              <a-input v-model:value='form.cotwoLow' placeholder='' allow-clear />
              <a-alert message="范围从10-36767" style="margin-top:1px;font-size: 9px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='CO2报警上限(ppm):' name='cotwoHigh'>
              <a-input v-model:value='form.cotwoHigh' placeholder='' allow-clear />
              <a-alert message="范围从10-36767" style="margin-top:1px;font-size: 9px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='NH3报警下限(ppm):' name='nhthreeLow'>
              <a-input v-model:value='form.nhthreeLow' placeholder='' allow-clear />
              <a-alert message="范围从0-500" style="margin-top:1px;font-size: 9px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='NH3报警上限(ppm):' name='nhthreeHigh'>
              <a-input v-model:value='form.nhthreeHigh' placeholder='' allow-clear />
              <a-alert message="范围从0-500" style="margin-top:1px;font-size: 9px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='H2S报警下限(ppm):' name='htwosLow'>
              <a-input v-model:value='form.htwosLow' placeholder='' allow-clear />
              <a-alert message="范围从0-500" style="margin-top:1px;font-size: 9px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='H2S报警上限(ppm):' name='htwosHigh'>
              <a-input v-model:value='form.htwosHigh' placeholder='' allow-clear />
              <a-alert message="范围从0-500" style="margin-top:1px;font-size: 9px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
          </a-col>
        </a-row>
        <a-divider >喷淋参数</a-divider>
        <a-alert  message="超级模式1含义是脉冲模式；超级模式2的含义是恢复常规喷淋模式；超级模式3含义是喷淋房模式" type="warning" />
        <a-row :gutter='8'>
          <a-col :md='11' :sm='24' :xs='24'>
            <a-form-item label='超级模式3(喷淋房模式)的喷淋模式' name='super3SprayMethod'>
              <a-radio-group v-model:value='form.super3SprayMethod'>
                <a-radio :value='0'>
                  一直喷
                </a-radio>
                <a-radio :value='1'>
                  交替循环喷淋
                </a-radio>
              </a-radio-group>
            </a-form-item>
            <a-form-item label='1/2小组和3/4小组交替喷淋的时间(秒):' name='super3AlternateTime'>
              <a-input v-model:value='form.super3AlternateTime' placeholder='' allow-clear />
            </a-form-item>
            <a-form-item label='220V提前24V开启的时间(秒):' name='v220Before24vTime'>
              <a-input v-model:value='form.v220Before24vTime' placeholder='' allow-clear />
            </a-form-item>
            <a-form-item label='220V延后24V关闭的时间(秒):' name='v220After24vTime'>
              <a-input v-model:value='form.v220After24vTime' placeholder='' allow-clear />
            </a-form-item>
          </a-col>
          <a-col :md='13' :sm='24' :xs='24'>
            <a-form-item label='超级模式1(脉冲模式)使能喷淋数据' name='super1ValidMode'>
              <a-radio-group v-model:value='form.super1ValidMode'>
                <a-radio :value='0'>
                  不使能
                </a-radio>
                <a-radio :value='1'>
                  喷淋数据A
                </a-radio>
                <a-radio :value='2'>
                  喷淋数据B
                </a-radio>
                <a-radio :value='3'>
                  喷淋数据C
                </a-radio>
                <a-radio :value='4'>
                  喷淋数据D
                </a-radio>
                <a-radio :value='5'>
                  喷淋数据E
                </a-radio>
                <a-radio :value='6'>
                  喷淋数据F
                </a-radio>
              </a-radio-group>
            </a-form-item>
            <a-form-item label='超级模式2(恢复常规喷淋模式)的使能数据:' name='super2ValidMode'>
              <a-radio-group v-model:value='form.super2ValidMode'>
                <a-radio :value='0'>
                  不使能
                </a-radio>
                <a-radio :value='1'>
                  喷淋数据A
                </a-radio>
                <a-radio :value='2'>
                  喷淋数据B
                </a-radio>
                <a-radio :value='3'>
                  喷淋数据C
                </a-radio>
                <a-radio :value='4'>
                  喷淋数据D
                </a-radio>
                <a-radio :value='5'>
                  喷淋数据E
                </a-radio>
                <a-radio :value='6'>
                  喷淋数据F
                </a-radio>
              </a-radio-group>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :md='1' :sm='24' :xs='24' />

          <a-col :md='2' :sm='24' :xs='24'>
            <a-form-item :wrapper-col='{ span: 12, offset: 5 }'>
              <a-button v-permission="['PROPERTY_DEVICELIST_MGR_SPRAYCTOCABINET_GLOBALCONFIG_SAVE_BUTTON']" type='primary' html-type='submit' :loading='iconLoading'>
                保存并同步
              </a-button>
            </a-form-item>
          </a-col>
          <a-col :md='1' :sm='24' :xs='24' />
          <a-col :md='2' :sm='24' :xs='24'>
            <a-form-item :wrapper-col='{ span: 12, offset: 5 }'>
              <a-button v-permission="['PROPERTY_DEVICELIST_MGR_SPRAYCTOCABINET_RESTART_BUTTON']" type='primary' html-type='button' @click='restartActionToCmdQueue' :loading='restartIconLoading'>
                重启设备
              </a-button>
            </a-form-item>
          </a-col>
          <a-col :md='1' :sm='24' :xs='24' />
          <a-col :md='2' :sm='24' :xs='24'>
            <a-form-item :wrapper-col='{ span: 12, offset: 5 }'>
              <a-button v-permission="['PROPERTY_DEVICELIST_MGR_SPRAYCTOCABINET_READ_CONFIG_BUTTON']" type='primary' html-type='button' @click='getParamsActionToCmdQueue' :loading='getParamsLoading'>
                读取设备的配置
              </a-button>
            </a-form-item>
          </a-col>
          <a-col :md='3' :sm='24' :xs='24' />
          <a-col :md='2' :sm='24' :xs='24'>
            <a-form-item :wrapper-col='{ span: 12, offset: 5 }'>
              <a-button v-permission="['PROPERTY_DEVICELIST_MGR_SPRAYCTOCABINET_CONFIG_READ_SIM_BUTTON']" type='primary' html-type='button' @click='getCcidToCmdQueue' :loading='getCcidLoading'>
                读取SIM卡信息
              </a-button>
            </a-form-item>
          </a-col>
          <a-col :md='10' :sm='24' :xs='24' />
        </a-row>
      </a-form>
    </a-card>
  </div>
</template>

<script>
import ClockCircleOutlined from '@ant-design/icons-vue/lib/icons/ClockCircleOutlined';
import { DeviceSprayConfigApi } from '@/api/property/DeviceSprayConfigApi';
import { DeviceSprayConfigQueueApi } from '@/api/property/DeviceSprayConfigQueueApi';
import { message } from 'ant-design-vue';
import {DeviceCommandDownQueueApi} from "@/api/property/DeviceCommandDownQueueApi";

export default {
  name: 'DeviceSprayCtocabinetConfigSwitchVthree',
  components: {
    ClockCircleOutlined
  },
  props: {
    data: Object
  },
  async mounted() {
  },
  async created() {
    await this.init();
  },
  data() {
    return {
      form: {},
      sourceForm: {},
      switchform: {},
      rules: {},
      iconLoading: false,
      loadTimer: '',
      restartIconLoading : false,
      restartLoadTimer : '',
      getParamsLoading : false,
      getParamsTimer : '',
      getCcidLoading : false,
      getCcidTimer : '',
    };
  },
  methods: {
    async init() {
      let _conf = await DeviceSprayConfigApi.detail({ 'recordId': this.data.recordId });
      if (_conf) {
        this.form = _conf;
        this.switchform.masterSwitchCheck = (_conf.masterSwitch == 1) ? true : false;
        this.switchform.fanHandSwitchCheck = (_conf.fanHandSwitch == 1) ? true : false;
        this.switchform.debugModelCheck = (_conf.debugModel == 1) ? true : false;
        this.switchform.cotwoSwitchCheck = (_conf.cotwoSwitch == 1) ? true : false;
        this.switchform.nhthreeSwitchCheck = (_conf.nhthreeSwitch == 1) ? true : false;
        this.switchform.htwosSwitchCheck = (_conf.htwosSwitch == 1) ? true : false;
        this.switchform.methaneSwitchCheck = (_conf.methaneSwitch == 1) ? true : false;
        console.log(this.form);
        this.sourceForm = Object.assign({}, _conf);
      }
    },
    masterSwitchChange(checked) {
      console.log(checked);
      this.switchform.masterSwitchCheck = checked;
    },
    fanHandSwitchChange(checked) {
      this.switchform.fanHandSwitchCheck = checked;
    },
    debugModelChange(checked) {
      this.switchform.debugModelCheck = checked;
    },
    cotwoSwitchChange(checked) {
      this.switchform.cotwoSwitchCheck = checked;
    },
    nhthreeSwitchChange(checked) {
      this.switchform.nhthreeSwitchCheck = checked;
    },
    htwosSwitchChange(checked) {
      this.switchform.htwosSwitchCheck = checked;
    },
    methaneSwitchChange(checked) {
      this.switchform.methaneSwitchCheck = checked;
    },
    checkProcess(sceneDictate, clearCallback, callback) {
      let params = {
        recordId: this.data.recordId,
        sceneDictate: sceneDictate
      };
      let result = DeviceCommandDownQueueApi.workingDetail(params);
      result
        .then(result => {
          if (!result || !result.dcdqId) { //处理完成了
            clearCallback && clearCallback(); //去掉菊花+清除循环调用
            callback && callback(); //用户自定义
          }
        })
        .catch(() => {
          clearCallback && clearCallback(); //去掉菊花+清除循环调用
        });
    },
    //begin重启----------------------
    clearRestartProcess(){
      this.restartIconLoading = false;
      clearInterval(this.restartLoadTimer);
    },
    checkRestartProcess()
    {
      let that = this;
      this.checkProcess(4, this.clearRestartProcess, function(){
        that.init();
      });
    },
    restartActionToCmdQueue()
    {
      let workerDetailparams = {
        recordId: this.data.recordId,
        sceneDictate: 4
      };
      let that = this;
      let existWorkerResult = DeviceCommandDownQueueApi.workingDetail2(workerDetailparams);
      existWorkerResult
        .then(workResult => {
          console.log(workResult);
          if (!workResult || !workResult.dcdqId) { //处理完成了
            that.restart();
          } else {
            message.error('上一个配置还在推送中，请稍后重试');
            return;
          }
        })
        .catch((e) => {
          message.error(e);
        });
    },
    restart () { //重启
      this.loading = true;
      let updateData = {
        old: '',
        update: '',
      };

      let updateDataRecord = {
        recordId: this.data.recordId,
        templateCode: 'sprayctocabinet',
        updateData: JSON.stringify(updateData),
        dictate : 4,
        sceneDictate : 4
      };

      let result = DeviceCommandDownQueueApi.add(updateDataRecord);
      result
        .then(result => {
          // 移除加载框
          this.loading = false;
          // 提示添加成功
          message.success(result.message);

          this.restartIconLoading = true; //转圈
          this.restartLoadTimer = setInterval(this.checkRestartProcess, 5000);
        })
        .catch(() => {
          this.loading = false;
        });
    },
    //end重启----------------------

    //保存数据---------begin
    clearConfigProcess(){
      this.iconLoading = false;
      clearInterval(this.loadTimer);
    },
    checkConfigProcess()
    {
      let that = this;
      this.checkProcess(9991, this.clearConfigProcess, function(){
        that.init();
      });
    },
    saveConfigToCmdQueue()
    {
      let workerDetailparams = {
        recordId: this.data.recordId,
        sceneDictate: 9991
      };
      let that = this;
      let existWorkerResult = DeviceCommandDownQueueApi.workingDetail2(workerDetailparams);
      existWorkerResult
        .then(workResult => {
          console.log(workResult);
          if (!workResult || !workResult.dcdqId) { //处理完成了
            that.save();
          } else {
            message.error('上一个配置还在推送中，请稍后重试');
            return;
          }
        })
        .catch((e) => {
          message.error(e);
        });
    },
    /**
     * 保存和编辑
     * 写到队列，队列发送完回写到原配置
     * @author cancan
     * @date 2022/03/04 21:15
     */
    save() {
      // this.form.masterSwitch = this.switchform.masterSwitchCheck ? 1 : 2;
      this.form.fanHandSwitch = this.switchform.fanHandSwitchCheck ? 1 : 2;
      this.form.debugModel = this.switchform.debugModelCheck ? 1 : 2;
      this.form.cotwoSwitch = this.switchform.cotwoSwitchCheck ? 1 : 2;
      this.form.nhthreeSwitch = this.switchform.nhthreeSwitchCheck ? 1 : 2;
      this.form.htwosSwitch = this.switchform.htwosSwitchCheck ? 1 : 2;
      this.form.methaneSwitch = this.switchform.methaneSwitchCheck ? 1 : 2;

      // if (this.form.fanModel == 2) {//温控模式
      //   if (this.form.fanTempCtoStart <= this.form.fanTempCtoOff) {
      //     message.error('风机在温控模式下的启动温度要大于停止温度，请重新输入');
      //     return;
      //   }
      // }

      if ((this.form.tempAlarmHigh != 0 && this.form.tempAlarmLow != 0) && this.form.tempAlarmHigh <= this.form.tempAlarmLow) {
        message.error('温度报警上限要大于下限，请重新输入');
        return;
      }

      if ((this.form.humAlarmHigh != 0 && this.form.humAlarmLow != 0) && this.form.humAlarmHigh <= this.form.humAlarmLow) {
        message.error('湿度报警上限要大于下限，请重新输入');
        return;
      }

      if ((this.form.methaneAlarmHigh != 0 && this.form.methaneAlarmLow != 0) && this.form.methaneAlarmHigh <= this.form.methaneAlarmLow) {
        message.error('甲烷报警上限要大于下限，请重新输入');
        return;
      }

      if ((this.form.cotwoHigh != 0 && this.form.cotwoLow != 0) && this.form.cotwoHigh <= this.form.cotwoLow) {
        message.error('CO2报警上限要大于下限，请重新输入');
        return;
      }

      if ((this.form.nhthreeHigh != 0 && this.form.nhthreeLow != 0) && this.form.nhthreeHigh <= this.form.nhthreeLow) {
        message.error('NH3报警上限要大于下限，请重新输入');
        return;
      }

      if ((this.form.htwosHigh !=0 && this.form.htwosLow !=0) && this.form.htwosHigh <= this.form.htwosLow) {
        message.error('H2S报警上限要大于下限，请重新输入');
        return;
      }

      if (this.data.clientInnerType == 3 && (this.form.super3OpenTemp !=0 && this.form.super3CloseTemp !=0) && this.form.super3OpenTemp <= this.form.super3CloseTemp) {
        message.error('超级模式3开启的温度要大于超级模式2关闭温度，请重新输入');
        return;
      }

      // 校验表单
      //await this.$refs.form.validate();

      // 修改加载框为正在加载
      this.loading = true;

      let updateData = {
        old: this.sourceForm,
        update: this.form
      };

      let updateDataRecord = {
        recordId: this.data.recordId,
        templateCode: 'sprayctocabinet',
        updateData: JSON.stringify(updateData),
        dictate : 9991,
        sceneDictate : 9991
      };

      let result = DeviceCommandDownQueueApi.add(updateDataRecord);
      result
        .then(result => {
          // 移除加载框
          this.loading = false;
          // 提示添加成功
          message.success(result.message);

          this.iconLoading = true; //转圈
          this.loadTimer = setInterval(this.checkConfigProcess, 5000);
        })
        .catch(() => {
          this.loading = false;
        });
    },
    //保存数据---------end

    //获取命令begin------------
    clearGetParamsProcess(){
      this.getParamsLoading = false;
      clearInterval(this.getParamsTimer);
    },
    checkGetParamsProcess()
    {
      let that = this;
      this.checkProcess(56, this.clearGetParamsProcess, function(){
        that.init();
      });
    },
    getParamsActionToCmdQueue()
    {
      let workerDetailparams = {
        recordId: this.data.recordId,
        sceneDictate: 56
      };
      let that = this;
      let existWorkerResult = DeviceCommandDownQueueApi.workingDetail2(workerDetailparams);
      existWorkerResult
        .then(workResult => {
          console.log(workResult);
          if (!workResult || !workResult.dcdqId) { //处理完成了
            that.getParams();
          } else {
            message.error('上一个配置还在推送中，请稍后重试');
            return;
          }
        })
        .catch((e) => {
          message.error(e);
        });
    },

    getParams() { //读取配置
      this.loading = true;
      let updateData = {
        old: '',
        update: '',
      };
      let updateDataRecord = {
        recordId: this.data.recordId,
        templateCode: 'sprayctocabinet',
        updateData: JSON.stringify(updateData),
        dictate : 56,
        sceneDictate : 56
      };

      let result = DeviceCommandDownQueueApi.add(updateDataRecord);
      result
        .then(result => {
          // 移除加载框
          this.loading = false;
          // 提示添加成功
          message.success(result.message);

          this.getParamsLoading = true; //转圈
          this.getParamsTimer = setInterval(this.checkGetParamsProcess, 5000);
        })
        .catch(() => {
          this.loading = false;
        });
    },
    //获取命令end---------------

    //获取CCID begin------------
    clearGetCcidProcess(){
      this.getCcidLoading = false;
      clearInterval(this.getCcidTimer);
    },
    checkGetCcidProcess()
    {
      let that = this;
      this.checkProcess(38, this.clearGetCcidProcess, function(){
        that.init();
      });
    },
    getCcidToCmdQueue()
    {
      let workerDetailparams = {
        recordId: this.data.recordId,
        sceneDictate: 38
      };
      let that = this;
      let existWorkerResult = DeviceCommandDownQueueApi.workingDetail2(workerDetailparams);
      existWorkerResult
        .then(workResult => {
          console.log(workResult);
          if (!workResult || !workResult.dcdqId) { //处理完成了
            that.getCcidRquest();
          } else {
            message.error('上一个配置还在推送中，请稍后重试');
            return;
          }
        })
        .catch((e) => {
          message.error(e);
        });
    },

    getCcidRquest() { //读取配置
      this.loading = true;
      let updateData = {
        old: '',
        update: '',
      };
      let updateDataRecord = {
        recordId: this.data.recordId,
        templateCode: 'sprayctocabinet',
        updateData: JSON.stringify(updateData),
        dictate : 38,
        sceneDictate : 38
      };

      let result = DeviceCommandDownQueueApi.add(updateDataRecord);
      result
        .then(result => {
          // 移除加载框
          this.loading = false;
          // 提示添加成功
          message.success(result.message);

          this.getCcidLoading = true; //转圈
          this.getCcidTimer = setInterval(this.checkGetCcidProcess, 5000);
        })
        .catch(() => {
          this.loading = false;
        });
    },
    //获取CCID end---------------
  }
};
</script>
<style scoped>
/** 用户卡片 */
.workplace-user-card .ele-cell-content {
  overflow: hidden;
}

.workplace-user-card h4 {
  margin-bottom: 6px;
}
</style>
